<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_list.css">
            <script src="js/a.js"></script>

</head>

<body>
    <div class="nav">
        <img src="img/head.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- spacer只是占位 -->
        <div class="spacer"></div>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.htm">写博客</a>
        <a href="logout">注销</a>
    </div>

    <!-- 这个div表示页面的主区域 -->
    <div class="container">
        <!-- 左侧内容区 -->
        <div class="container-left">
            <div class="card">
                <!-- 用户的头像 -->
                <img src="img/dog2.jpg" alt="">
                <!-- 用户的名字 -->
                <h3>我的博客</h3>
                <a href="#">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span class="count">--</span>
                    <span class="sort">--</span>
                </div>
            </div>
        </div>
        <!-- 右侧内容区 -->
        <div class="container-right">
            <!-- 每个.blg用来表示一篇博客
            <div class="blog">
                <div class="title">我的第一篇博客</div>
                <div class="date">2022-11-06 12:00:00</div>
                <div class="desc">
                    这是我的第一篇博客里面包含了我的自我介绍Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis adipisci ipsam velit eaque, dolores delectus necessitatibus ab distinctio facilis mollitia nulla voluptatibus, earum accusamus sit expedita id, deleniti est veritatis.
                </div>
                <a href="blog_detail.html">查看全文 &gt;&gt;</a>
            </div> -->

        </div>
    </div>

    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script>
        function getBlogList() {
            $.ajax({
                type: "get",
                url: "blog",
                success: function (body) {
                    let containerDiv = document.querySelector(".container-right");
                    for (let blog of body) {
                        //为每篇博客创建一个blogDiv
                        let blogDiv = document.createElement("div");
                        blogDiv.className = "blog";

                        //博客的标题
                        let titleDiv = document.createElement("div");
                        titleDiv.className = "title";
                        titleDiv.innerHTML = blog.title;

                        //博客发布时间
                        let postTime = document.createElement("div");
                        postTime.className = "date";
                        postTime.innerHTML = blog.postTime;

                        //博客正文
                        let contentDiv = document.createElement("div");
                        contentDiv.className = "desc";
                        contentDiv.innerHTML = blog.content;

                        //查看全文
                        let a = document.createElement("a");
                        a.href = 'blog_detail.html?blogId=' + blog.blogId;
                        a.innerHTML = "查看全文 &gt;&gt;";

                        //将新建的标签拼接起来构成一个完整的博客列表
                        blogDiv.appendChild(titleDiv);
                        blogDiv.appendChild(postTime);
                        blogDiv.appendChild(contentDiv);
                        blogDiv.appendChild(a);

                        containerDiv.appendChild(blogDiv);

                    }
                }
            });
        }

        //获取登录用户的详情信息
        function getUserInfo() {
            $.ajax({
                type:'get',
                url:'userInfo' + location.search,
                success:function(body) {
                    let h3 = document.querySelector('.container-left>.card>h3');
                    h3.innerHTML = body.username;

                    let a = document.querySelector(".container-left>.card>a");
                    a.href = body.github;

            
                }
            })
        }

        getUserInfo();

        getBlogList();
        getLoginStatus();

    </script>

</body>

</html>